import { tagList } from '@/api/article'

export default {
    namespaced: true, // 是否开启命名空间
    // data 存储数据
    state: {
        tagList:[],
    },
    // 异步
    actions: {
        getTags({commit}){
            tagList()
                .then(res=>{
                    commit('setTag',res.data)
                })
        },
    },
    mutations:{
        setTag(state,data){
            state.tagList = data
        }
    },
    getters: {
        getTagList(state){
          return state.tagList
        },
        getTagData(state){
            let tagData = {}
            if(state.tagList.length===0)return tagData
            state.tagList.forEach(item=>{
                tagData[item.id] = item.name
            })
            return tagData
        },
    }
}